/**
 * Created by LC on 2019/11/21
 */
package com.hw.paltfrom.service.mainscreen;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hw.paltfrom.mapper.HwCaseMainMapper;
import com.hw.paltfrom.mapper.HwCommandTaskMapper;
import com.hw.paltfrom.pojo.HwCaseMain;
import com.hw.paltfrom.pojo.HwCommandTask;
import com.hw.paltfrom.rescode.HWSystemCode;
import com.hw.paltfrom.utils.ResponeResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class StationCountService {
    @Autowired
    private HwCaseMainMapper caseMainMapper;

    @Autowired
    private HwCommandTaskMapper commandTaskMapper;
    /**
     * 执法监管：全部执行中、本月已完结。
     * 指挥调度：本年创建的移交（闯卡移交、逃逸移交）、异地复检。
     * @return
     */
    public Map<String, Object> queryCount(String overrunCode) {
        //返回数据
        Map<String,Integer> map = new HashMap<>();
        //执法监管全部执行中
        Wrapper<HwCaseMain> caseMainWrapper = new EntityWrapper<>();
        caseMainWrapper.eq("F_OverrunCode",overrunCode).ne("F_AJ_CrtStep","07");
        Integer executingCaseNum = caseMainMapper.selectCount(caseMainWrapper);
        map.put("executingCaseNum",executingCaseNum);
        //执法监管本月已完结
        //本月数据
        Calendar currentMonth=Calendar.getInstance();
        currentMonth.add(Calendar.MONTH,0);
        currentMonth.set(Calendar.DAY_OF_MONTH,1);
        currentMonth.set(Calendar.HOUR_OF_DAY,0);
        currentMonth.set(Calendar.MINUTE,0);
        currentMonth.set(Calendar.SECOND,0);
        Date thisMonthTime=currentMonth.getTime();
        Wrapper<HwCaseMain> caseMainWrapper2 = new EntityWrapper<>();
        caseMainWrapper2.eq("F_OverrunCode",overrunCode).eq("F_AJ_CrtStep","07").between("F_AJ_EndTime",thisMonthTime,new Date());
        Integer finishedCaseNum = caseMainMapper.selectCount(caseMainWrapper2);
        map.put("finishedCaseNum",finishedCaseNum);
        //指挥调度:本年创建的闯卡移交
        Calendar currentYear=Calendar.getInstance();
        currentYear.add(Calendar.YEAR,0);
        currentYear.set(Calendar.MONTH,0);
        currentYear.set(Calendar.DAY_OF_MONTH,1);
        currentYear.set(Calendar.HOUR_OF_DAY,0);
        currentYear.set(Calendar.MINUTE,0);
        currentYear.set(Calendar.SECOND,0);
        Date thisYearTime = currentYear.getTime();
        //闯卡移交筛选条件
        Wrapper<HwCommandTask> commandTaskWrapper = new EntityWrapper<>();
        commandTaskWrapper.eq("F_FromDepCode",overrunCode).eq("Task_Type","02").between("F_CreateTime",thisYearTime,new Date());
        Integer ckyjCaseNum = commandTaskMapper.selectCount(commandTaskWrapper);
        map.put("ckyjCaseNum",ckyjCaseNum);
        //指挥调度:本年创建的逃逸移交
        //逃逸移交筛选条件
        Wrapper<HwCommandTask> commandTaskWrapper2 = new EntityWrapper<>();
        commandTaskWrapper2.eq("F_FromDepCode",overrunCode).eq("Task_Type","03").between("F_CreateTime",thisYearTime,new Date());
        Integer tyyjCaseNum = commandTaskMapper.selectCount(commandTaskWrapper2);
        map.put("tyyjCaseNum",tyyjCaseNum);
        //指挥调度:本年创建的异地复检
        //逃逸移交筛选条件
        Wrapper<HwCommandTask> commandTaskWrapper3 = new EntityWrapper<>();
        commandTaskWrapper3.eq("F_FromDepCode",overrunCode).eq("Task_Type","01").between("F_CreateTime",thisYearTime,new Date());
        Integer ydfjCaseNum = commandTaskMapper.selectCount(commandTaskWrapper3);
        map.put("ydfjCaseNum",ydfjCaseNum);
        return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS,map);
    }
}
